package com.front.controller;


import com.front.util.BaseController;
import com.front.util.Result;
import com.aaa.vo.PagePlugin;
import com.front.entity.UserAndStore;
import com.front.service.UserAndStoreService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;


@RestController
@RequestMapping("userAndStore")
public class UserAndStoreController extends BaseController {
    /**
     * 服务对象
     */
    @Resource
    private UserAndStoreService userAndStoreService;

    /**
     * 根据用户名和店铺名查询
     * @param
     * @param
     * @return
     */
    @GetMapping("selectByStoreIdAndUserId")
    public Result selectByStoreIdAndUserId(@RequestParam Integer storeId,@RequestParam Integer userId){
        return success(userAndStoreService.selectByStoreIdAndUserId(userId,storeId));

    }



    /**
     * 分页查询所有数据
     * <p>
     * 如果需要带参数分页请前往Impl中添加
     *
     * @param page 分页对象
     * @return 所有数据
     */
    @PostMapping("queryPage")
    public Result queryPage(@RequestBody PagePlugin<UserAndStore> page) {
        return success(this.userAndStoreService.queryPage(page));
    }

    /**
     * 查询所有数据
     */
    @GetMapping("/queryAll")
    public Result queryAll() {
        return success(this.userAndStoreService.list());
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("/queryById")
    public Result queryById(Integer id) {
        return success(this.userAndStoreService.getById(id));
    }

    /**
     * 新增数据
     *
     * @param storeId 实体对象
     * @return 新增结果
     */
    @PostMapping("add")
    public Result insert(@RequestParam Integer storeId,@RequestParam Integer userId) {

        UserAndStore userAndStore = new UserAndStore(userId,storeId);
        return success(this.userAndStoreService.save(userAndStore));
    }

    /**
     * 修改数据
     *
     * @param userAndStore 实体对象
     * @return 修改结果
     */
    @PostMapping("update")
    public Result update(@RequestBody UserAndStore userAndStore) {
        return success(this.userAndStoreService.updateById(userAndStore));
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除结果
     */
    @DeleteMapping("deleteById")
    public Result delete(Integer id) {
        return success(this.userAndStoreService.removeById(id));
    }
}

